package com.hxzy.module.store.controller;

import com.hxzy.framework.common.resp.R;
import com.hxzy.framework.common.resp.ResultCode;
import com.hxzy.framework.web.util.WebFrameworkUtils;
import com.hxzy.module.store.api.store.resp.StoreAccountResp;
import com.hxzy.module.store.entity.StoreAccount;
import com.hxzy.module.store.mapstruct.StoreAccountMapStruct;
import com.hxzy.module.store.service.StoreAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Author wy
 * @Description TODO
 * @Date 2024/1/26 9:25
 * @Version 1.0
 */
@RestController
@Api(tags = "门店模块-门店账号Api")
@RequestMapping("/storeAccount")
public class StoreAccountController {

    @Autowired
    private StoreAccountService  storeAccountService;

    @ApiOperation(value = "根据账号查询")
    @GetMapping(value = "/find/{account}")
    public R<StoreAccountResp> findByCount(@PathVariable(value = "account") String account ){
        Long merchantId = WebFrameworkUtils.getMerchantId();
        StoreAccount storeAccount=this.storeAccountService.findByCount(account,merchantId);
        if(Objects.nonNull(storeAccount)) {
            //StoreAccount转换StoreAccountResp  (mapstruct)
            return R.success(StoreAccountMapStruct.INSTANCE.convert(storeAccount));
        }
        return R.failed(ResultCode.DATA_NOT_FOUND);
    }

}
